package com.comdo.newup_loan.module.store;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import com.comdo.newup_loan.R;
import com.comdo.newup_loan.adapter.MemberListAdapter;
import com.comdo.newup_loan.base.BaseActivity;
import com.comdo.newup_loan.comom.Config;
import com.comdo.newup_loan.model.MemberBean;
import com.comdo.newup_loan.util.TitleMenuUtil;
import com.comdo.newup_loan.widget.MyItemDecoration;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created by liyuan on 2017/11/6.
 */

public class StoreDetailActivity extends BaseActivity<StoreDetailPersenter> implements StoreDetailContact.View{
    private MemberListAdapter memberListAdapter;
    @BindView(R.id.recyclerview)
    RecyclerView mRecyclerView;
    @BindView(R.id.tv_depart_name)
    TextView mDepartText;
    @BindView(R.id.tv_adress)
    TextView mAdressText;
    private List<MemberBean.MemberItemBean> listData;
    @Override
    protected int getContentViewLayoutID() {
        return R.layout.activity_store_detail;
    }
    @Override
    protected void init() {
        super.init();
        mPresenter.getList(Config.loginInfo.getUserId(),getIntent().getIntExtra("id",0));
    }
    @Override
    protected void initView(Bundle savedInstanceState) {
        new TitleMenuUtil(StoreDetailActivity.this,"门店详情",true);
        LinearLayoutManager layoutManager = new LinearLayoutManager(StoreDetailActivity.this);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        mRecyclerView.setLayoutManager(layoutManager);
        mRecyclerView.addItemDecoration(new MyItemDecoration());
        listData=new ArrayList<MemberBean.MemberItemBean>();
        memberListAdapter = new MemberListAdapter(listData,StoreDetailActivity.this);
        mRecyclerView.setAdapter(memberListAdapter);

    }
    @Override
    public StoreDetailPersenter getmPresenter() {
        return new StoreDetailPersenter();
    }

    @Override
    public void presenterSetView() {
        if (mPresenter != null)
            mPresenter.setView(this);
    }

    @Override
    public void getFail(String failMessage) {
        showToast(failMessage);
    }

    @Override
    public void getList(MemberBean datas) {
        mAdressText.setText(datas.getAddress());
        mDepartText.setText(datas.getDeptName());
        listData.clear();
        listData.addAll(datas.getStaffList());
        memberListAdapter.notifyDataSetChanged();
    }
}
